package com.hnguigu.health.houduan.lcj.controller_lcj;

import com.google.gson.Gson;
import com.hnguigu.health.houduan.lcj.pojo_lcj.TSetmealCheckgroup_lcj;
import com.hnguigu.health.houduan.lcj.pojo_lcj.TSetmeal_lcj;
import com.hnguigu.health.houduan.lcj.service_lcj.TSetmealCheckgroupService_lcj;
import com.hnguigu.health.houduan.lcj.service_lcj.TSetmealService_lcj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/tsetcheckgroup")
public class TSetmealCheckgroupCpntroller_lcj {
    @Autowired(required = false)
    TSetmealCheckgroupService_lcj tsmcg;

    @Autowired(required = false)
    TSetmealService_lcj tset;

    @GetMapping("/updsmcg")
    @ResponseBody
    public Integer updsmcg(String setid,String checkid,String tim,String tsetmeal){
        List<TSetmealCheckgroup_lcj> bySetID = tsmcg.getBySetID(setid);
        String aa= bySetID.get(0).getCreatetime();
        int i = tsmcg.delBysetid(setid);
        String[] split = checkid.split(",");
        if(i>0){
            TSetmealCheckgroup_lcj tSetmealCheckgroup_lcj = new TSetmealCheckgroup_lcj();
            for (int j=0;j<split.length;j++){
                tSetmealCheckgroup_lcj.setSetmealId(Integer.valueOf(setid));
                tSetmealCheckgroup_lcj.setCheckgroupId(Integer.valueOf(split[j]));
                tSetmealCheckgroup_lcj.setCreatetime(aa);
                tSetmealCheckgroup_lcj.setUpdatetime(tim);
                tsmcg.addtsetCheck(tSetmealCheckgroup_lcj);
            }
        }
        Gson gson = new Gson();
        TSetmeal_lcj o = gson.fromJson(tsetmeal,TSetmeal_lcj.class);
        o.setUpdatetine(tim);
        tset.updateByPrimaryKeySelective(o);
        return 1;
    }
}
